package com.lohika.vvrublevskyy.dao.impl.mapers;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;

import com.lohika.vvrublevskyy.model.User;

public class UserRowMaper implements RowMapper<User> {

	@Override
	public User mapRow(ResultSet resultSet, int rowNum) throws SQLException {
		User user = new User();
		user.setID(resultSet.getLong("id"));
		user.setUsername(resultSet.getString("username"));
		user.setName(resultSet.getString("name"));
		user.setPassword(resultSet.getString("password"));
		return user;
	}
	
	public SqlParameterSource getMap(User user){
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("username", user.getUsername());
		parameters.put("name", user.getName());
		parameters.put("password", user.getPassword());
		parameters.put("ID", user.getID());
		SqlParameterSource parametersSource = new MapSqlParameterSource(parameters);
		return parametersSource;
	}

}
